﻿using System;
using System.Data;
using System.Text;

namespace BUL
{
    public static class exten
    {
        public static DataTable GetData()
        {
            var dtb = new DataTable();
            //Tạo các Columns
            dtb.Columns.Add("TagName");
            dtb.Columns.Add("Weight");
            dtb.Columns.Add("HrefUrl");
            //Thêm các bản ghi
            dtb.Rows.Add("asp.net", 12, "http://hmweb.com.vn/aspnet.aspx");
            dtb.Rows.Add("khương", 12, "http://hmweb.com.vn");
            dtb.Rows.Add("SQL", 11, "http://hmweb.com.vn/SQL-server.aspx");
            dtb.Rows.Add("Accessibility", 12, "http://hmweb.com.vn/Accessibility.aspx");
            dtb.Rows.Add("Ajax", 12, "http://hmweb.com.vn/Ajax.aspx");
            dtb.Rows.Add("Csharp", 13, "http://hmweb.com.vn/Csharp.aspx");
            dtb.Rows.Add("Hướng", 16, "http://hmweb.com.vn/OTDH.aspx");
            dtb.Rows.Add("jquery", 11, "http://hmweb.com.vn/jquery.aspx");
            dtb.Rows.Add("Store", 9, "http://hmweb.com.vn/Store.aspx");
            dtb.Rows.Add("Hiền", 17, "http://hmweb.com.vn/Facebook.aspx");
            dtb.Rows.Add("Microsoft", 17, "http://hmweb.com.vn/Microsoft.aspx");
            dtb.Rows.Add("google", 12, "http://hmweb.com.vn/google.aspx");
            dtb.Rows.Add("silverlight", 13, "http://hmweb.com.vn/silverlight.aspx");
            dtb.Rows.Add("VTV2", 13, "http://hmweb.com.vn/VTV2.aspx");
            dtb.Rows.Add("Phân trang", 11, "http://hmweb.com.vn/phan-trang.aspx");
            dtb.Rows.Add("Toán", 16, "http://hmweb.com.vn/Toan.aspx");
            dtb.Rows.Add("Lý", 16, "http://hmweb.com.vn/Ly.aspx");
            dtb.Rows.Add("hà", 16, "http://hmweb.com.vn/Hoa.aspx");
            dtb.Rows.Add("TV Online", 12, "http://hmweb.com.vn/hmweb-truyen-hinh-truc-tuyen.aspx");
            return dtb;
        }
    

    public static string CatChuoi(this string s, int length)
                    {
                        if (String.IsNullOrEmpty(s))
                            throw new ArgumentNullException(s);
                        var words = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (words[0].Length > length)
                            throw new ArgumentException("Từ đầu tiên dài hơn chuỗi cần cắt");
                        var sb = new StringBuilder();
                        foreach (var word in words)
                        {
                            if ((sb + word).Length > length)
                                return string.Format("{0} ...", sb.ToString().TrimEnd(' '));
                            sb.Append(word + " ");
                        }
                        return string.Format("{0} ...", sb.ToString().TrimEnd(' '));
                    }
       }
    }

